package com.zhijian.warehouse.manage.controller;

import com.zhijian.response.annotation.Response;
import com.zhijian.warehouse.manage.entity.vo.request.*;
import com.zhijian.warehouse.manage.service.ExcelExportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;

/**
 * 通道门设置 控制层
 *
 * @author auto
 * @version 1.0
 * @date 2024-11-03 15:31:18
 */
@Slf4j
@Controller
@Api(tags = "导出excel")
@RequestMapping("/excel/export")
public class ExcelExportController {
    @Autowired
    private ExcelExportService excelExportService;

    /**
     * 仪器领用归还记录
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/access/product/record")
    @ApiOperation("仪器领用归还记录")
    public void selectByCondition(
            HttpServletResponse response,
            @RequestBody(required = false) AccessProductRecordSearchVo param) {
        if (param == null)
            param = AccessProductRecordSearchVo.builder().build();
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        excelExportService.accessProductExport(param, response);
    }

    /**
     * 违规领用记录
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/access/facility/record/illegal")
    @ApiOperation("导出-违规领用记录")
    public void selectIllegalByCondition(HttpServletResponse response,
                                         @RequestBody(required = false) AccessFacilityRecordSearchVo param) {
        if (param == null)
            param = AccessFacilityRecordSearchVo.builder().build();
        log.info("{} - {}| selectIllegalByCondition export info", this.getClass().getSimpleName(), param);
        param.setIsViolator(1);
        excelExportService.illegalExport(param, response);
    }

    /**
     * 超期未归还记录
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/access/product/record/overdue")
    @ApiOperation("导出-超期未归还记录")
    public void selectOverdueByCondition(HttpServletResponse response,
                                         @RequestBody(required = false) AccessProductRecordSearchVo param) {
        if (param == null)
            param = AccessProductRecordSearchVo.builder().build();
        log.info("{} - {}| selectOverdueByCondition export info", this.getClass().getSimpleName(), param);
        excelExportService.overdueExport(param, response);
    }

    /**
     * 通道门进出记录
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/access/facility/record")
    @ApiOperation("导出-通道门进出记录")
    public void accessFacilityExport(
            HttpServletResponse response,
            @RequestBody(required = false) AccessFacilityRecordSearchVo param) {
        if (param == null)
            param = AccessFacilityRecordSearchVo.builder().build();
        log.info("{} - {}| accessFacilityExport export info", this.getClass().getSimpleName(), param);
        excelExportService.accessFacilityExport(response, param);
    }

    /**
     * 产品入库
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/store/in/record")
    @ApiOperation("导出-产品入库")
    public void storeInExport(
            HttpServletResponse response,
            @RequestBody(required = false) StoreRecordSearchVo param) {
        if (param == null)
            param = StoreRecordSearchVo.builder().build();
        log.info("{} - {}| storeInExport export info", this.getClass().getSimpleName(), param);
        excelExportService.storeInExport(response, param);
    }

    /**
     * 产品出库
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/store/out/record")
    @ApiOperation("导出-产品出库")
    public void storeOutExport(
            HttpServletResponse response,
            @RequestBody(required = false) StoreOutRecordSearchVo param) {
        if (param == null)
            param = StoreOutRecordSearchVo.builder().build();
        log.info("{} - {}| storeInExport export info", this.getClass().getSimpleName(), param);
        excelExportService.storeOutExport(response, param);
    }


    /**
     * 产品出入库查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/store/opt/detail/record")
    @ApiOperation("导出-首页-下载表格")
    public void storeOptDetailExport(
            HttpServletResponse response,
            @RequestBody(required = false) StoreOptRecordSearchVo param) {
        if (param == null)
            param = StoreOptRecordSearchVo.builder().build();
        log.info("{} - {}| storeOptExport export info", this.getClass().getSimpleName(), param);
        excelExportService.storeOptDetailExport(response, param);
    }


    /**
     * 产品出入库查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/store/opt/record")
    @ApiOperation("导出-产品出入库查询")
    public void storeOptExport(
            HttpServletResponse response,
            @RequestBody(required = false) StoreOptRecordSearchVo param) {
        if (param == null)
            param = StoreOptRecordSearchVo.builder().build();
        log.info("{} - {}| storeOptExport export info", this.getClass().getSimpleName(), param);
        excelExportService.storeOptExport(response, param);
    }

    /**
     * 库存查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/store/record")
    @ApiOperation("导出-库存查询")
    public void storeExport(
            HttpServletResponse response,
            @RequestBody(required = false) StoreSearchVo param) {
        if (param == null)
            param = StoreSearchVo.builder().build();
        log.info("{} - {}| storeExport export info", this.getClass().getSimpleName(), param);
        excelExportService.storeExport(response, param);
    }


    /**
     * 产品盘点详情导出
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/store/stock/detail/ex")
    @ApiOperation("导出-产品盘点详情导出")
    public void storeStockDetailExport(
            HttpServletResponse response,
            @RequestBody StoreStockRecordSaveOrUpdateVo param
    ) {
        if (param == null)
            param = StoreStockRecordSaveOrUpdateVo.builder().build();
        log.info("{} - {}| storeStockDetailExport export info", this.getClass().getSimpleName(), param);
        excelExportService.storeStockDetailExport(response, param);
    }
}
